﻿using System;
using System.Text;
using HslCommunication.Core;

namespace HslCommunication.Robot.FANUC
{
	/// <summary>
	/// Fanuc机器人的报警对象
	/// </summary>
	// Token: 0x02000032 RID: 50
	public class FanucAlarm
	{
		/// <summary>
		/// AlarmID
		/// </summary>
		// Token: 0x170000A3 RID: 163
		// (get) Token: 0x0600039C RID: 924 RVA: 0x0000EA9C File Offset: 0x0000CC9C
		// (set) Token: 0x0600039D RID: 925 RVA: 0x0000EAA4 File Offset: 0x0000CCA4
		public short AlarmID { get; set; }

		/// <summary>
		/// AlarmNumber
		/// </summary>
		// Token: 0x170000A4 RID: 164
		// (get) Token: 0x0600039E RID: 926 RVA: 0x0000EAAD File Offset: 0x0000CCAD
		// (set) Token: 0x0600039F RID: 927 RVA: 0x0000EAB5 File Offset: 0x0000CCB5
		public short AlarmNumber { get; set; }

		/// <summary>
		/// CauseAlarmID
		/// </summary>
		// Token: 0x170000A5 RID: 165
		// (get) Token: 0x060003A0 RID: 928 RVA: 0x0000EABE File Offset: 0x0000CCBE
		// (set) Token: 0x060003A1 RID: 929 RVA: 0x0000EAC6 File Offset: 0x0000CCC6
		public short CauseAlarmID { get; set; }

		/// <summary>
		/// CauseAlarmNumber
		/// </summary>
		// Token: 0x170000A6 RID: 166
		// (get) Token: 0x060003A2 RID: 930 RVA: 0x0000EACF File Offset: 0x0000CCCF
		// (set) Token: 0x060003A3 RID: 931 RVA: 0x0000EAD7 File Offset: 0x0000CCD7
		public short CauseAlarmNumber { get; set; }

		/// <summary>
		/// Severity
		/// </summary>
		// Token: 0x170000A7 RID: 167
		// (get) Token: 0x060003A4 RID: 932 RVA: 0x0000EAE0 File Offset: 0x0000CCE0
		// (set) Token: 0x060003A5 RID: 933 RVA: 0x0000EAE8 File Offset: 0x0000CCE8
		public short Severity { get; set; }

		/// <summary>
		/// Time
		/// </summary>
		// Token: 0x170000A8 RID: 168
		// (get) Token: 0x060003A6 RID: 934 RVA: 0x0000EAF1 File Offset: 0x0000CCF1
		// (set) Token: 0x060003A7 RID: 935 RVA: 0x0000EAF9 File Offset: 0x0000CCF9
		public DateTime Time { get; set; }

		/// <summary>
		/// AlarmMessage
		/// </summary>
		// Token: 0x170000A9 RID: 169
		// (get) Token: 0x060003A8 RID: 936 RVA: 0x0000EB02 File Offset: 0x0000CD02
		// (set) Token: 0x060003A9 RID: 937 RVA: 0x0000EB0A File Offset: 0x0000CD0A
		public string AlarmMessage { get; set; }

		/// <summary>
		/// CauseAlarmMessage
		/// </summary>
		// Token: 0x170000AA RID: 170
		// (get) Token: 0x060003AA RID: 938 RVA: 0x0000EB13 File Offset: 0x0000CD13
		// (set) Token: 0x060003AB RID: 939 RVA: 0x0000EB1B File Offset: 0x0000CD1B
		public string CauseAlarmMessage { get; set; }

		/// <summary>
		/// SeverityMessage
		/// </summary>
		// Token: 0x170000AB RID: 171
		// (get) Token: 0x060003AC RID: 940 RVA: 0x0000EB24 File Offset: 0x0000CD24
		// (set) Token: 0x060003AD RID: 941 RVA: 0x0000EB2C File Offset: 0x0000CD2C
		public string SeverityMessage { get; set; }

		/// <summary>
		/// 从字节数据加载真实的信息
		/// </summary>
		/// <param name="byteTransform">字节变换</param>
		/// <param name="content">原始的字节内容</param>
		/// <param name="index">索引</param>
		/// <param name="encoding">编码</param>
		// Token: 0x060003AE RID: 942 RVA: 0x0000EB38 File Offset: 0x0000CD38
		public void LoadByContent(IByteTransform byteTransform, byte[] content, int index, Encoding encoding)
		{
			this.AlarmID = BitConverter.ToInt16(content, index);
			this.AlarmNumber = BitConverter.ToInt16(content, index + 2);
			this.CauseAlarmID = BitConverter.ToInt16(content, index + 4);
			this.CauseAlarmNumber = BitConverter.ToInt16(content, index + 6);
			this.Severity = BitConverter.ToInt16(content, index + 8);
			bool flag = BitConverter.ToInt16(content, index + 10) > 0;
			if (flag)
			{
				this.Time = new DateTime((int)BitConverter.ToInt16(content, index + 10), (int)BitConverter.ToInt16(content, index + 12), (int)BitConverter.ToInt16(content, index + 14), (int)BitConverter.ToInt16(content, index + 16), (int)BitConverter.ToInt16(content, index + 18), (int)BitConverter.ToInt16(content, index + 20));
			}
			this.AlarmMessage = encoding.GetString(content, index + 22, 80).Trim(new char[1]);
			this.CauseAlarmMessage = encoding.GetString(content, index + 102, 80).Trim(new char[1]);
			this.SeverityMessage = encoding.GetString(content, index + 182, 18).Trim(new char[1]);
		}

		/// <inheritdoc />
		// Token: 0x060003AF RID: 943 RVA: 0x0000EC54 File Offset: 0x0000CE54
		public override string ToString()
		{
			return string.Format("FanucAlarm ID[{0},{1},{2},{3},{4}]{5}{6}{7}{8}{9}{10}", new object[]
			{
				this.AlarmID,
				this.AlarmNumber,
				this.CauseAlarmID,
				this.CauseAlarmNumber,
				this.Severity,
				Environment.NewLine,
				this.AlarmMessage,
				Environment.NewLine,
				this.CauseAlarmMessage,
				Environment.NewLine,
				this.SeverityMessage
			});
		}

		/// <summary>
		/// 从数据内容创建报警信息
		/// </summary>
		/// <param name="byteTransform">字节变换</param>
		/// <param name="content">原始的字节内容</param>
		/// <param name="index">索引</param>
		/// <param name="encoding">编码</param>
		/// <returns>报警信息</returns>
		// Token: 0x060003B0 RID: 944 RVA: 0x0000ECF0 File Offset: 0x0000CEF0
		public static FanucAlarm PraseFrom(IByteTransform byteTransform, byte[] content, int index, Encoding encoding)
		{
			FanucAlarm fanucAlarm = new FanucAlarm();
			fanucAlarm.LoadByContent(byteTransform, content, index, encoding);
			return fanucAlarm;
		}
	}
}
